
window.onload =function() {
	var oMenu = document.getElementById("menu");
	var aMenu = oMenu.getElementsByClassName("span-more");
	var aMenu2 = oMenu.getElementsByClassName("regu");
	var oName = document.getElementById("username");
	var oPwd = document.getElementById("pwd");
	//alert(oMenu);
	//alert(aMenu2.length);



	for(var i=0; i<aMenu.length; i++) {
		aMenu[i].value=i;
		//alert("1");
		aMenu[i].onclick =function() {
			for(var j=0; j<aMenu.length; j++) {
				aMenu[j].getElementsByClassName("show")[0].className="show";
			}
			aMenu[this.value].getElementsByClassName("show")[0].className="show selected2";
			//alert(this.value);
		}

	}

	for(var i=0; i<aMenu2.length; i++) {
		aMenu2[i].value=i;
		//alert("1");
		aMenu2[i].onclick =function() {
			for(var j=0; j<aMenu2.length; j++) {
				aMenu2[j].className="regu";
			}
			aMenu2[this.value].className="regu selected3";
			//alert(this.value);
		}

	}

	function initMenu() {
		$('#menu ul').hide();
		$('#menu ul:first').show();
		$('#menu li span').click(
				function() {
					var checkElement = $(this).next();
					if((checkElement.is('ul')) && (checkElement.is(':visible'))) {
						return false;
					}
					if((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
						$('#menu ul:visible').slideUp('normal');
						checkElement.slideDown('normal');
						return false;
					}
				}
		);
	}
	$(document).ready(function() {initMenu();});




}

//show the login dialog
function show() {
	var oLayer = document.getElementById("layer");
	var oLogin = document.getElementById("login");
	oLayer.style.display="block";
	oLogin.style.display="block";
}
function offs() {
	var oLayer = document.getElementById("layer");
	var oLogin = document.getElementById("login");
	oLayer.style.display="none";
	oLogin.style.display="none";
}
//login action
function logins() {
	var flag = false;
	var UserName = document.getElementById("username").value;
	var Pwd =document.getElementById("pwd").value;
	if(UserName!="" && Pwd!="") {
		doSomething(UserName, Pwd);
	} else {
		alert("用户账户或密码填写不完整");
	}
}
function logins2() {
	alert("登陆成功");
//	document.getElementById("login-reg").innerHTML='<input type="button" value="退出" onclick="quit()" id="quit" />';
	var oLogin1 = document.getElementById("login1");
	var oQuit = document.getElementById("quit");
//	var oManInfoA = document.getElementById("man-info-a");
//	var oManInfo = document.getElementById("man-info");
	oLogin1.style.display ="none";
	oQuit.style.display ="block";
//	oManInfo.style.display ="block";
//	oManInfoA.style.display ="block";
}
function quit() {
	var oLogin1 = document.getElementById("login1");
	var oQuit = document.getElementById("quit");
//	var oManInfoA = document.getElementById("man-info-a");
//	var oManInfo = document.getElementById("man-info");
	oLogin1.style.display ="block";
	oQuit.style.display ="none";
//	oManInfo.style.display ="none";
//	oManInfoA.style.display ="none";
	logout();
}

function logout() {
	createXMLHttpRequest();
	var url = "index!logout.php";
	xmlRequest.open("get", url, true);
	xmlRequest.setRequestHeader("Context-Type","application/x-www-form-urlencoded");
	xmlRequest.onreadystatechange = function() {
		if(xmlRequest.readyState == 4) {
			if(xmlRequest.status == 200) {
				//	document.getElementById("login-reg").innerHTML='<input type="button" value="登录" onclick="show()" id="login1" />';
				var oLogin1 = document.getElementById("login1");
				var oQuit = document.getElementById("quit");
				oQuit.style.display ="none";
				oLogin1.style.display ="block";
				alert("退出登录");
			}else {
				window.alert("系统开小差....");
			}
		}
	};
	xmlRequest.send(null);
}

var xmlRequest;
function createXMLHttpRequest() {
	if(window.XMLHttpRequest) {
		// DOM 2 Browser
		xmlRequest = new XMLHttpRequest();
	}else if(window.ActiveXObject) {
		try {
			xmlRequest = new ActiveXObject("Msxml2.XMLHTTP");
		}catch(e) {
			try {
				xmlRequest = new ActiveXObject("Microsoft.XMLHTTP");
			}catch(e){}
		}
	}
}
function doSomething(username,password) {
	createXMLHttpRequest();
	var uri = "index.php?username="+username +"&password="+password;
	xmlRequest.open("post", uri, true);
	xmlRequest.setRequestHeader("Context-Type","application/x-www-form-urlencoded");
	xmlRequest.onreadystatechange = function() {
		if(xmlRequest.readyState == 4) {
			if(xmlRequest.status == 200) {
				var res = xmlRequest.responseText;

				if(res) {
					offs();
					logins2();
				}else {
					alert("用户名或密码错误！");
				}

			}else {
				window.alert("系统开小差....");
			}
		}
	};
	xmlRequest.send(null);
}

$(function(){  
	supportPlaceholder='placeholder'in document.createElement('input'),
	placeholder=function(input){                    
		var text = input.attr('placeholder'),
		defaultValue = input.defaultValue;                    
		if(!defaultValue){                     
			input.val(text).addClass("phcolor");
		}                     
		input.focus(function(){                     
			if(input.val() == text){                       
				$(this).val("");
			}
		});                                        
		input.blur(function(){                     
			if(input.val() == ""){                           
				$(this).val(text).addClass("phcolor");
			}
		});                     
		input.keydown(function(){                      
			$(this).removeClass("phcolor");
		});
	};                     
	if(!supportPlaceholder){                     
		$('input').each(function(){                     
			text = $(this).attr("placeholder");                     
			if($(this).attr("type") == "text"){                    
				placeholder($(this));
			} else if($(this).attr("type") == "password"){                   
				placeholder($(this));
			}
		});
	}                     
});

onmouseup="changeTxt()"